/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.gac.gacmod.visual;

import org.gac.gacmod.model.*;

/**
 *
 * @author Tomek
 */
public class SceneFactory {

    public StepWidgetBase CreateWidgets( BoxScene scene, Step rootStep )
    {
        if( rootStep == null )
            return null;
        
        if( rootStep instanceof AtomicStep )
        {
            return new AtomicStepWidget(scene, rootStep);
        }
        else
        {
            if( rootStep instanceof SequenceStep )
            {
                SequenceStepWidget result = new SequenceStepWidget(scene, rootStep);
                for( Step s: ((CompositeStep)rootStep).InnerSteps())
                {
                    result.addInnerStep(CreateWidgets( scene, s ));
                }
                return result;
            }
            else if( rootStep instanceof SplitStep)
            {
                SplitStepWidget result = new SplitStepWidget(scene, rootStep);
                for( Step s: ((CompositeStep)rootStep).InnerSteps())
                {
                    result.addInnerStep(CreateWidgets( scene, s ));
                }
                return result;
            }
            else if( rootStep instanceof RepeatStep)
            {
                RepeatStepWidget result = new RepeatStepWidget(scene, rootStep);
                for( Step s: ((CompositeStep)rootStep).InnerSteps())
                {
                    result.addInnerStep(CreateWidgets( scene, s ));
                }
                return result;
            }
            else
                throw new UnsupportedOperationException("Unknown root step!");
        }

    }
    
}
